<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <!-- <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <a-col :span="6">
            <a-form-item :label="$t('m.system.announcement.entity.titile')">
              <a-input placeholder="" v-model="queryParam.titile"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item :label="$t('m.system.announcement.entity.sender')">
              <a-input placeholder="" v-model="queryParam.sender"></a-input>
            </a-form-item>
          </a-col>

          <a-col :span="8" >
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" class="blue-btn" @click="getsysMessList" icon="search">{{ $t('m.common.button.query') }}</a-button>
              <a-button type="default" @click="getsysMessList" icon="reload" style="margin-left: 8px">{{ $t('m.common.button.reset') }}</a-button>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div> -->

    <!-- <div class="table-operator">
      <a-button type="primary" class="blue-btn" @click="readAll" icon="book">{{$t('m.system.announcement.other.readall')}}</a-button>
    </div> -->

    <!-- <a-table
      ref="table"
      size="default"
      bordered
      rowKey="id"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="ipagination"
      :loading="loading"
      @change="handleTableChange">
      <span slot="action" slot-scope="text, record">
        <a-button type="primary" class="blue-btn" style="margin-bottom: 5px;" @click="jumpRouter(record)">跳转</a-button>
        <a-button type="primary" class="blue-btn" style="margin-left: 8px" @click="markRead(record)">设为已读</a-button>
      </span>
    </a-table> -->
    <commpVxeTable
      :key="reCommpVxeTable"
      :config="dataTableConfig"
      :columns="columns"
      :formItem="formItem"
      ref="administrativeOffice"
      @searchEvent="searchEvent"
      @resetEvent="resetEvent"
      >
      <template v-slot:externalOperations="{data}"  >
        <vxe-form-item>
          <template>
            <a-button type="primary" class="blue-btn" @click="readAll" icon="book">{{$t('m.system.announcement.other.readall')}}</a-button>
          </template>
        </vxe-form-item>
      </template>
      <template v-slot:operation_btn="{row}" data-desc="自定操作栏">
        <a-button type="primary" class="blue-btn" style="margin-bottom: 5px;" @click="jumpRouter(row)">跳转</a-button>
        <a-button type="primary" class="blue-btn" style="margin-left: 8px" @click="markRead(row)">设为已读</a-button>
      </template>
    </commpVxeTable>
    <show-announcement ref="ShowAnnouncement"></show-announcement>
    <dynamic-notice ref="showDynamNotice" :path="openPath" :formData="formData"/>
  </a-card>
</template>

<script>

  import { getAction,putAction,sysMessList,getMessage,getTzMessage } from '@/api/manage'
  import commpVxeTable from '@/components/commp-vxe-table/commp-vxe-table.vue'
  import ShowAnnouncement from '@/framework/tools/ShowAnnouncement'
  import {YcListMixin} from '@/mixins/YcListMixin'
  import DynamicNotice from '../../framework/tools/DynamicNotice'
  import YchConstant from "@/api/YchConstant";
  import LocaleUtil from "../../utils/LocaleUtil";

  export default {
    name: "UserAnnouncementList",
    mixins: [YcListMixin],
    components: {
      DynamicNotice,
      ShowAnnouncement,
      commpVxeTable
    },
    data () {
      return {
        description: '系统通告表管理页面',
        reCommpVxeTable: '',
        dataTableConfig: {
          api: YchConstant.SPZX_OA + '/sysTzMessage/list',
          rowId: 'id',
          urlType: true,
          paramet: {}
        },
        queryParam: {},
        // columns: [{
        //   title: this.$t('m.system.announcement.entity.titile'),
        //   align:"center",
        //   field: 'titile'
        // },{
        //   title: this.$t('m.system.announcement.entity.msgCategory'),
        //   align: "center",
        //   field: 'msgCategory',
        //   customRender: function (text) {
        //     if (text == '1') {
        //       return LocaleUtil.getLocale('m.system.announcement.other.msgCategory_option1')
        //     } else if (text == "2") {
        //       return LocaleUtil.getLocale('m.system.announcement.other.msgCategory_option2')
        //     } else {
        //       return text;
        //     }
        //   }
        // },{
        //   title: this.$t('m.system.announcement.entity.sender'),
        //   align:"center",
        //   field: 'sender'
        // },{
        //   title: this.$t('m.system.announcement.entity.sendTime'),
        //   align:"center",
        //   field: 'sendTime'
        // },{
        //   title: this.$t('m.system.announcement.entity.priority'),
        //   align:"center",
        //   field: 'priority',
        //   customRender:function (text) {
        //     if(text=='L'){
        //       return LocaleUtil.getLocale('m.system.announcement.other.priority_option1')
        //     }else if(text=="M"){
        //       return LocaleUtil.getLocale('m.system.announcement.other.priority_option2')
        //     }else if(text=="H"){
        //       return LocaleUtil.getLocale('m.system.announcement.other.priority_option3')
        //     } else {
        //       return text;
        //     }
        //   }
        // },{
        //   title: this.$t('m.system.announcement.entity.readFlag'),
        //   align:"center",
        //   field: 'readFlag',
        //   customRender:function (text) {
        //     if(text=='0'){
        //       return LocaleUtil.getLocale('m.system.announcement.other.no_read')
        //     }else if(text=="1"){
        //       return LocaleUtil.getLocale('m.system.announcement.other.have_read')
        //     } else {
        //       return text;
        //     }
        //   }
        // },{
        //   title: this.$t('m.common.label.operate'),
        //   field: 'action',
        //   align:"center",
        //   scopedSlots: { customRender: 'action' },
        // }],
        columns:[
          {
            title: '事项类型',
            align:"center",
            field: 'ftzsxlx',
            width: 100,
          },{
            title: '事项完成时间',
            align:"center",
            field: 'fsxwcsj',
            width: 150,
          },{
            title: '事项名称',
            align:"center",
            field: 'fsxmc'
          },{
            title: '事项信息',
            align:"center",
            field: 'fmessage'
          },{
            title: '操作',
            align:"center",
            field: 'id',
            width: 200,
            slots: {
            // 使用插槽模板渲染
              default: 'operation_btn',
            },
          },
        ],
        formItem: [
        {
          label: '事项类型',
          model: 'ftzsxlx',
          placeholder: '通知事项信息类型',
          type:'Select',
          dictionaryType:'通知事项信息类型'
        },
      ],
        dataSource: [],
		    url: {
          list: YchConstant.PREFIX_SYSTEM + "/sysAnnouncementSend/getMyAnnouncementSend",
          editCementSend:YchConstant.PREFIX_SYSTEM + "/sysAnnouncementSend/editByAnntIdAndUserId",
          readAllMsg:YchConstant.PREFIX_SYSTEM + "/sysAnnouncementSend/readAll",
        },
        loading:false,
        openPath:'',
        formData:'',

        //
        idList: [],
        //
        routerList: [
          {
            'ftzsxlx':'OA办公',
            'lcmcList': [
              {
                'flcmc':'自治区食品药品审评查验中心干部职工离岗请示（请假）登记流程',
                'zbhjList': [
                  {
                    'fzbhj':'离岗申请',
                    'path': '/administrativeOffice/departureRequest/leaveApplication/index'
                  },{
                    'fzbhj':'科室审批',
                    'path': '/administrativeOffice/departureRequest/leaveApplication/index1'
                  },{
                    'fzbhj':'分管领导审批',
                    'path': '/administrativeOffice/departureRequest/leaveApplication/index2'
                  },{
                    'fzbhj':'销假',
                    'path': '/administrativeOffice/departureRequest/leaveApplication/index4'
                  }
                ]
              },{
                'flcmc':'xx壮族自治区食品药品审评查验申请事项审批表',
                'zbhjList': [
                  {
                    'fzbhj':'起草',
                    'path': '/administrativeOffice/applyFor/applicationReview/index'
                  },{
                    'fzbhj':'科室审核',
                    'path': '/administrativeOffice/applyFor/applicationReview/index1'
                  },{
                    'fzbhj':'办公室意见',
                    'path': '/administrativeOffice/applyFor/applicationReview/index2'
                  },{
                    'fzbhj':'中心分管领导审核',
                    'path': '/administrativeOffice/applyFor/applicationReview/index4'
                  },{
                    'fzbhj':'中心主要领导审核',
                    'path': '/administrativeOffice/applyFor/applicationReview/index3'
                  }
                ]
              },{
                'flcmc':'自治区食品药品审评查验中心网站信息发布审批表',
                'zbhjList': [
                  {
                    'fzbhj':'申请',
                    'path': '/administrativeOffice/websiteInformation/informationRelease/index'
                  },{
                    'fzbhj':'科室审批',
                    'path': '/administrativeOffice/websiteInformation/informationRelease/index1'
                  },{
                    'fzbhj':'办公室审批',
                    'path': '/administrativeOffice/websiteInformation/informationRelease/index2'
                  },{
                    'fzbhj':'中心分管领导审批',
                    'path': '/administrativeOffice/websiteInformation/informationRelease/index3'
                  },{
                    'fzbhj':'中心主任审批',
                    'path': '/administrativeOffice/websiteInformation/informationRelease/index4'
                  }
                ]
              },{
                'flcmc':'自治区食品药品审评查验中心会议保障登记',
                'zbhjList': [
                  {
                    'fzbhj':'申请确认',
                    'path': '/administrativeOffice/conferenceRoomManagement/meetingRoomApplication/index'
                  },{
                    'fzbhj':'科室审批',
                    'path': '/administrativeOffice/conferenceRoomManagement/meetingRoomApplication/index1'
                  },{
                    'fzbhj':'办公室审批',
                    'path': '/administrativeOffice/conferenceRoomManagement/meetingRoomApplication/index2'
                  },{
                    'fzbhj':'会议安排',
                    'path': '/administrativeOffice/conferenceRoomManagement/meetingRoomApplication/index3'
                  }
                ]
              },{
                'flcmc':'办公用品申请管理流程',
                'zbhjList': [
                  {
                    'fzbhj':'申请',
                    'path': '/administrativeOffice/officeSupplies/approve/index'
                  },{
                    'fzbhj':'科室审批',
                    'path': '/administrativeOffice/officeSupplies/approve/index1'
                  },{
                    'fzbhj':'办公室确认',
                    'path': '/administrativeOffice/officeSupplies/approve/index2'
                  }
                ]
              },{
                'flcmc':'加班值班管理',
                'zbhjList': [
                  {
                    'fzbhj':'申请',
                    'path': '/administrativeOffice/workOvertime/index/index'
                  },{
                    'fzbhj':'科室审批',
                    'path': '/administrativeOffice/workOvertime/superior/index'
                  },{
                    'fzbhj':'分管审批',
                    'path': '/administrativeOffice/workOvertime/superior/index1'
                  },{
                    'fzbhj':'单位领导审批',
                    'path': '/administrativeOffice/workOvertime/superior/index2'
                  },{
                    'fzbhj':'加班办理',
                    'path': '/administrativeOffice/workOvertime/superior/index3'
                  }
                ]
              },{
                'flcmc':'请休假管理',
                'zbhjList': [
                  {
                    'fzbhj':'请假申请',
                    'path': '/administrativeOffice/holiday/index/index'
                  },{
                    'fzbhj':'科室审批',
                    'path': '/administrativeOffice/holiday/higherLevel/index'
                  },{
                    'fzbhj':'人事审批',
                    'path': '/administrativeOffice/holiday/higherLevel/index1'
                  },{
                    'fzbhj':'分管审批',
                    'path': '/administrativeOffice/holiday/higherLevel/index2'
                  },{
                    'fzbhj':'中心领导审批',
                    'path': '/administrativeOffice/holiday/higherLevel/index3'
                  },{
                    'fzbhj':'请假确认',
                    'path': '/administrativeOffice/holiday/higherLevel/index4'
                  }
                ]
              },{
                'flcmc':'xx壮族自治区食品药品审评查验中心文件',
                'zbhjList': []
              },{
                'flcmc':'xx壮族自治区食品药品审评查验中心文件处理笺',
                'zbhjList': []
              }
            ]
          }
        ]
      }
    },
    created() {
      // this.getsysMessList()
    },
    methods: {
      // handleDetail: function(record){
      //   this.$refs.sysAnnouncementModal.detail(record);
      //   this.$refs.sysAnnouncementModal.title=this.$t('m.common.title.detail');
      // },
      // showAnnouncement(record){
      //   putAction(this.url.editCementSend,{anntId:record.anntId}).then((res)=>{
      //     if(res.success){
      //       this.loadData();
      //       this.syncHeadNotic(record.anntId)
      //     }
      //   });
      //   if(record.openType==='component'){
      //     this.openPath = record.openPage;
      //     this.formData = {id:record.busId};
      //     this.$refs.showDynamNotice.detail();
      //   }else{
      //     this.$refs.ShowAnnouncement.detail(record);
      //   }
      // },
      // syncHeadNotic(anntId){
      //   getAction(YchConstant.PREFIX_SYSTEM + "/annountCement/syncNotic",{anntId:anntId})
      // },
      readAll(){

        var that = this;
        that.loading = true
        that.$confirm({
          title:that.$t('m.common.title.operate'),
          content:that.$t('m.system.announcement.verify.readall_confirm'),
          onOk: function(){
            // putAction(that.url.readAllMsg).then((res)=>{
            //   if(res.success){
            //     that.messageUtil.success(res.message);
            //     that.loadData();
            //     that.syncHeadNotic();
            //   }
            // });
            let list = that.idList.toString()
            getTzMessage({ids:list}).then(res => {
              //console.log('readAll',res)

              if(res.code == 200){
                that.loading = false
                that.getsysMessList()
              } else {
                that.$message.error(res.message)
              }
            })
          },
          onCancel() {
            that.loading = false
          },
        });
      },
      // 获取未读消息列表
      getsysMessList(){
        this.loading = true
        sysMessList().then(res => {
          // //console.log(res)
          if(res.code == 200){
            this.loading = false
            this.dataSource = res.result.records
            //console.log('dataSource',this.dataSource)
            this.idList = []
            this.dataSource.forEach(item => {
              this.idList.push(item.id)
            })
            //console.log('idList',this.idList)
            this.$store.dispatch('UpdateMessagesNum', res.result.total)
          } else {
            this.$message.error(res.message)
          }
        })
      },
      // 跳转
      jumpRouter(record){
        //console.log(record)
        this.routerList.forEach(itema => {
          if(record.ftzsxlx == itema.ftzsxlx){
            itema.lcmcList.forEach(itemb => {
              if(record.flcmc == itemb.flcmc){
                itemb.zbhjList.forEach(itemc => {
                  if(record.fzbhj == itemc.fzbhj){
                    this.$router.push({
                      path: itemc.path,
                    }).catch(err => {});
                  }
                })
              }
            })
          }
        })
      },
      //
      markRead(record){
        //console.log(record)
        this.loading = true
        getMessage({id:record.id}).then(res => {
          if(res.code == 200){
            this.loading = false
            this.getsysMessList()
            this.$store.dispatch('UpdateMessagesNum', !this.$store.state.permission.messagesNum)
            // this.getsysMessList()
            this.reCommpVxeTable = Date.now()
          } else {
            this.$message.error(res.message)
          }
        })
      },
          // 搜索
    searchEvent(){
        this.dataTableConfig.paramet = {
          ...this.dataTableConfig.paramet,
        }
        //console.log(this.dataTableConfig.paramet)
    },
    // 重置
    resetEvent(){
        this.dataTableConfig.paramet = {
          ...this.dataTableConfig.paramet,
        }
    },
    }
  }
</script>
<style lang="less" scoped>
.blue-btn{
    border: 1px solid #5ca3e5 !important;
    background-color: #5ca3e5 !important;
    color: #fff !important;
}
  .ant-card-body .table-operator{
    margin-bottom: 18px;
  }
  .anty-row-operator button{margin: 0 5px}
  .ant-btn-danger{background-color: #ffffff}z

  .ant-modal-cust-warp{height: 100%}
  .ant-modal-cust-warp .ant-modal-body{height:calc(100% - 110px) !important;overflow-y: auto}
  .ant-modal-cust-warp .ant-modal-content{height:90% !important;overflow-y: hidden}
</style>
